package demo3;

public class My_Thread03 {
    public static void main(String[] args) {
        //创建Runnable的实例
        MyRunnable myRunnable = new MyRunnable();
        //创建线程
        Thread thread = new Thread(myRunnable);
        //启动线程, 创建PCB, 参与CPU调度
        thread.start();

        //主线程中的任务
        while (true) {
            try {
                //休眠1000毫秒
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello main thread...");
        }
    }
}

//单独定义了线程的任务
class MyRunnable implements Runnable {
    // 实现具体的任务
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello my runnable...");
        }
    }
}
